package com.supermarket.web.controller.supermarket;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import com.supermarket.business.domain.SupermarketInventoryChange;
import com.supermarket.business.dto.SupermarketInventoryChangeDTO;
import com.supermarket.business.vo.SupermarketInventoryChangeVO;
import org.springframework.beans.BeanUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.supermarket.common.annotation.Log;
import com.supermarket.common.core.controller.BaseController;
import com.supermarket.common.core.domain.AjaxResult;
import com.supermarket.common.enums.BusinessType;
import com.supermarket.business.service.ISupermarketInventoryChangeService;
import com.supermarket.common.utils.poi.ExcelUtil;
import com.supermarket.common.core.page.TableDataInfo;

/**
 * 库存变动Controller
 * 
 * @author ruoyi
 * @date 2025-07-21
 */
@RestController
@RequestMapping("/supermarket/change")
public class SupermarketInventoryChangeController extends BaseController
{
    @Resource
    private ISupermarketInventoryChangeService sysInventoryChangeService;

    /**
     * 查询库存变动列表
     */
    @PreAuthorize("@ss.hasPermi('supermarket:change:list')")
    @GetMapping("/list")
    public TableDataInfo list(SupermarketInventoryChangeDTO supermarketInventoryChangeDTO)
    {
        startPage();
        SupermarketInventoryChange supermarketInventoryChange = new SupermarketInventoryChange();
        BeanUtils.copyProperties(supermarketInventoryChangeDTO, supermarketInventoryChange);
        List<SupermarketInventoryChange> list = sysInventoryChangeService.selectSysInventoryChangeList(supermarketInventoryChange);
        return getDataTable(list);
    }

    /**
     * 导出库存变动列表
     */
    @PreAuthorize("@ss.hasPermi('supermarket:change:export')")
    @Log(title = "库存变动", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SupermarketInventoryChange supermarketInventoryChange)
    {
        List<SupermarketInventoryChange> list = sysInventoryChangeService.selectSysInventoryChangeList(supermarketInventoryChange);
        ExcelUtil<SupermarketInventoryChange> util = new ExcelUtil<SupermarketInventoryChange>(SupermarketInventoryChange.class);
        util.exportExcel(response, list, "库存变动数据");
    }

    /**
     * 获取库存变动详细信息
     */
    @PreAuthorize("@ss.hasPermi('supermarket:change:query')")
    @GetMapping(value = "/{changeId}")
    public AjaxResult getInfo(@PathVariable("changeId") Long changeId)
    {
        return success(sysInventoryChangeService.selectSysInventoryChangeVOByChangeId(changeId));
    }

    /**
     * 新增库存变动
     */
    @PreAuthorize("@ss.hasPermi('supermarket:change:add')")
    @Log(title = "库存变动", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SupermarketInventoryChangeDTO supermarketInventoryChangeDTO)
    {
        SupermarketInventoryChange supermarketInventoryChange = new SupermarketInventoryChange();
        BeanUtils.copyProperties(supermarketInventoryChangeDTO, supermarketInventoryChange);
        return toAjax(sysInventoryChangeService.insertSysInventoryChange(supermarketInventoryChange));
    }

    /**
     * 修改库存变动
     */
    @PreAuthorize("@ss.hasPermi('supermarket:change:edit')")
    @Log(title = "库存变动", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SupermarketInventoryChangeDTO supermarketInventoryChangeDTO)
    {
        SupermarketInventoryChange supermarketInventoryChange = new SupermarketInventoryChange();
        BeanUtils.copyProperties(supermarketInventoryChangeDTO, supermarketInventoryChange);
        return toAjax(sysInventoryChangeService.updateSysInventoryChange(supermarketInventoryChange));
    }

    /**
     * 删除库存变动
     */
    @PreAuthorize("@ss.hasPermi('supermarket:change:remove')")
    @Log(title = "库存变动", businessType = BusinessType.DELETE)
	@DeleteMapping("/{changeIds}")
    public AjaxResult remove(@PathVariable Long[] changeIds)
    {
        return toAjax(sysInventoryChangeService.deleteSysInventoryChangeByChangeIds(changeIds));
    }
}
